package com.xll.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.xll.entity.BloodPressure;
import com.xll.entity.Kidney;
import com.xll.entity.MedicalExamination;
import com.xll.mapper.BloodPressureMapper;
import com.xll.mapper.KidneyMapper;
import com.xll.mapper.MedicalExaminationMapper;
import com.xll.service.BloodPressureService;
import com.xll.service.KidneyService;
import com.xll.service.PDFService;
import com.xll.utils.QueryInfo;
import com.xll.utils.Result;
import com.xll.utils.SecurityUtils;
import com.xll.utils.WatermarkingEventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestBody;


import java.io.IOException;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class PDFServiceImpl  implements PDFService {

    @Autowired
    private BloodPressureService bloodPressureService;
    @Autowired
    private BloodPressureMapper bloodPressureMapper;
    @Autowired
    private MedicalExaminationMapper medicalExaminationMapper;
    @Autowired
    private KidneyMapper kidneyMapper;

    @Autowired
    private KidneyService kidneyService;

    @Override
    public void PDF(PdfDocument pdfDoc,String query) throws IOException {
        Document doc = new Document(pdfDoc, PageSize.A4);// 构建文档对象
        doc.setMargins(20, 45, 15, 45);

//        PdfFont font = PdfFontFactory.createFont("C://Windows//Fonts//simsun.ttc,1", PdfEncodings.IDENTITY_H,true);
        PdfFont font = PdfFontFactory.createFont(ResourceUtils.getURL("classpath:static").getPath() + "/font/msyh.ttc,0", PdfEncodings.IDENTITY_H,true);

        String path = ResourceUtils.getURL("classpath:static")
                .getPath() + "/font/111.jpg";
        //设置水印
        pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE,
                new WatermarkingEventHandler(font,
                        path,
                        WatermarkingEventHandler.WATER_IMG));
        generateInfo(doc, font,query);


        // 表尾
        Table lastTable = new Table(15).setWidth(UnitValue.createPercentValue(100));
        String name = "xll";


//        lastTable.addCell(new Cell(1, 7).add(new Paragraph("制表人: " + name).setTextAlignment(TextAlignment.LEFT)
//                .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));
//        lastTable.addCell(new Cell(1, 8).add(new Paragraph("制表日期: " + DateUtils.getDateTime()).setTextAlignment(TextAlignment.RIGHT)
//                .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));

        doc.add(lastTable);
        doc.close();
        pdfDoc.close();
    }

    @Override
    public void InnerInfo(PdfDocument pdfDoc, String query) throws IOException {
        Document doc = new Document(pdfDoc, PageSize.A4);// 构建文档对象
        doc.setMargins(20, 45, 15, 45);

//        PdfFont font = PdfFontFactory.createFont("C://Windows//Fonts//simsun.ttc,1", PdfEncodings.IDENTITY_H,true);
        PdfFont font = PdfFontFactory.createFont(ResourceUtils.getURL("classpath:static").getPath() + "/font/msyh.ttc,0", PdfEncodings.IDENTITY_H,true);

        String path = ResourceUtils.getURL("classpath:static")
                .getPath() + "/font/111.jpg";
        //设置水印
        pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE,
                new WatermarkingEventHandler(font,
                        path,
                        WatermarkingEventHandler.WATER_IMG));
        generateInnerInfo(doc, font,query);


        // 表尾
        Table lastTable = new Table(15).setWidth(UnitValue.createPercentValue(100));


        doc.add(lastTable);
        doc.close();
        pdfDoc.close();
    }

    @Override
    public void KidneyInfo(PdfDocument pdfDoc,String query) throws IOException {
        Document doc = new Document(pdfDoc, PageSize.A4);// 构建文档对象
        doc.setMargins(20, 45, 15, 45);

//        PdfFont font = PdfFontFactory.createFont("C://Windows//Fonts//simsun.ttc,1", PdfEncodings.IDENTITY_H,true);
        PdfFont font = PdfFontFactory.createFont(ResourceUtils.getURL("classpath:static").getPath() + "/font/msyh.ttc,0", PdfEncodings.IDENTITY_H,true);

        String path = ResourceUtils.getURL("classpath:static")
                .getPath() + "/font/111.jpg";
        //设置水印
        pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE,
                new WatermarkingEventHandler(font,
                        path,
                        WatermarkingEventHandler.WATER_IMG));
        KidneyInfo(doc, font,query);


        // 表尾
        Table lastTable = new Table(15).setWidth(UnitValue.createPercentValue(100));


        doc.add(lastTable);
        doc.close();
        pdfDoc.close();
    }

    @Override
    public void CellInfo(PdfDocument pdfDoc) throws IOException {
        Document doc = new Document(pdfDoc, PageSize.A4);// 构建文档对象
        doc.setMargins(20, 45, 15, 45);

//        PdfFont font = PdfFontFactory.createFont("C://Windows//Fonts//simsun.ttc,1", PdfEncodings.IDENTITY_H,true);
        PdfFont font = PdfFontFactory.createFont(ResourceUtils.getURL("classpath:static").getPath() + "/font/msyh.ttc,0", PdfEncodings.IDENTITY_H,true);

        String path = ResourceUtils.getURL("classpath:static")
                .getPath() + "/font/111.jpg";
        //设置水印
        pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE,
                new WatermarkingEventHandler(font,
                        path,
                        WatermarkingEventHandler.WATER_IMG));
        CellInfo(doc, font);


        // 表尾
        Table lastTable = new Table(15).setWidth(UnitValue.createPercentValue(100));


        doc.add(lastTable);
        doc.close();
        pdfDoc.close();
    }

    private void generateInfo(Document doc, PdfFont font,String query) {
        Table table = new Table(15).setWidth(UnitValue.createPercentValue(100));
        DecimalFormat df = new DecimalFormat("###,##0.00");

        String title = "人体血压健康表打印";



        table.addCell(new Cell(1, 15).add(new Paragraph(title+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        table.addCell(new Cell(1, 4).add(new Paragraph("分类").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("收缩压（mmHG）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("舒张压（mmHG）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 4).add(new Paragraph("正常血压").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("<120").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("<80").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));



        table.addCell(new Cell(1, 4).add(new Paragraph("正常高值").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("120-138").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和（或）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("80-89").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 4).add(new Paragraph("高血压").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph(">=140").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和（或）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph(">=90").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 4).add(new Paragraph("1级高血压").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("140-159").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和（或）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("90-99").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 4).add(new Paragraph("2级高血压").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("160-179").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和（或）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("100-109").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 4).add(new Paragraph("3级高血压").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph(">=180").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("和（或）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph(">=110").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        String title1="本次打印的体检记录";
        table.addCell(new Cell(1, 15).add(new Paragraph("\n"+title+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        Page<BloodPressure> page = bloodPressureMapper.findPage(query);
        table.addCell(new Cell(1, 4).add(new Paragraph("舒张压（mmHG）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("收缩压（mmHG）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("体检时间").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("体检者").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        for (int i = 0; i < page.size(); i++) {
            table.addCell(new Cell(1, 4).add(new Paragraph(String.valueOf(page.get(i).getLow())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 4).add(new Paragraph(String.valueOf(page.get(i).getHigh())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 3).add(new Paragraph(page.get(i).getCreateTime()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 4).add(new Paragraph(page.get(i).getPeople()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        }

        String remark = "注意防范！";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate localDate = LocalDate.now();






        table.addCell(new Cell(1, 15).add(new Paragraph(remark).setTextAlignment(
                TextAlignment.LEFT).setFont(font).setFontSize(11)).setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 15).add(new Paragraph("制表日期: " + localDate).setTextAlignment(TextAlignment.RIGHT)
               .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));
        doc.add(table);
    }

    private void generateInnerInfo(Document doc, PdfFont font,String query) {
        Table table = new Table(15).setWidth(UnitValue.createPercentValue(100));
        DecimalFormat df = new DecimalFormat("###,##0.00");

        String title = "内科检查表打印";



        table.addCell(new Cell(1, 15).add(new Paragraph(title+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        Page<MedicalExamination> page = medicalExaminationMapper.findPage(query);
        table.addCell(new Cell(1, 1).add(new Paragraph("心率").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("肺部").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("心音").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("心律").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("腹部").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("肝脏").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("脾脏 ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("神经系统").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("其它").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("体检时间").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 1).add(new Paragraph("体检者").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        for (int i = 0; i < page.size(); i++) {
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getRate()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getLungs()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getSounds()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getFrequency()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getAbdomen()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(page.get(i).getLiver()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(page.get(i).getSpleen()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getNervous()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(page.get(i).getOther()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(page.get(i).getCreateTime()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 1).add(new Paragraph(page.get(i).getPeople()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        }

        String remark = "注意防范！";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate localDate = LocalDate.now();






        table.addCell(new Cell(1, 15).add(new Paragraph(remark).setTextAlignment(
                TextAlignment.LEFT).setFont(font).setFontSize(11)).setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 15).add(new Paragraph("制表日期: " + localDate).setTextAlignment(TextAlignment.RIGHT)
                .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));
        doc.add(table);
    }


    private void  KidneyInfo(Document doc, PdfFont font,String query) {
        Table table = new Table(15).setWidth(UnitValue.createPercentValue(100));
        DecimalFormat df = new DecimalFormat("###,##0.00");

        String title = "肾脏检查表打印";



        table.addCell(new Cell(1, 15).add(new Paragraph(title+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        table.addCell(new Cell(1, 5).add(new Paragraph("项目名称").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("参考范围").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("单位").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));



        table.addCell(new Cell(1, 5).add(new Paragraph("葡萄糖(GLU) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("4.10-5.90").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("mmol/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("尿素  ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("3.20-7.30 ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("mmol/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("肌酐(CREAT)   ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("57-97  ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("umol/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("尿酸UA  ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("210-430").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("umol/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        String title1="记录明细";
        table.addCell(new Cell(1, 15).add(new Paragraph("\n"+title1+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        List<Kidney> page = kidneyService.findByName(query);
        table.addCell(new Cell(1, 2).add(new Paragraph("葡萄糖(GLU) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("尿素").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("肌酐(CREAT)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 2).add(new Paragraph("尿酸UA").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 4).add(new Paragraph("检查时间").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 3).add(new Paragraph("检查者").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        for (int i = 0; i < page.size(); i++) {
            table.addCell(new Cell(1, 2).add(new Paragraph(String.valueOf(page.get(i).getGlu())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(String.valueOf(page.get(i).getUrea())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 2).add(new Paragraph(String.valueOf(page.get(i).getCreat())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

            table.addCell(new Cell(1, 2).add(new Paragraph(String.valueOf(page.get(i).getUa())).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 4).add(new Paragraph(page.get(i).getCreateTime()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
            table.addCell(new Cell(1, 3).add(new Paragraph(page.get(i).getPeople()).setTextAlignment(
                    TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        }

        String remark = "注意防范！";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate localDate = LocalDate.now();



        table.addCell(new Cell(1, 15).add(new Paragraph(remark).setTextAlignment(
                TextAlignment.LEFT).setFont(font).setFontSize(11)).setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 15).add(new Paragraph("制表日期: " + localDate).setTextAlignment(TextAlignment.RIGHT)
                .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));
        doc.add(table);
    }

    private void  CellInfo(Document doc, PdfFont font) {
        Table table = new Table(15).setWidth(UnitValue.createPercentValue(100));
        DecimalFormat df = new DecimalFormat("###,##0.00");

        String title = "血压检查标准表打印";



        table.addCell(new Cell(1, 15).add(new Paragraph(title+"\n").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(18)).setBorder(Border.NO_BORDER));

        table.addCell(new Cell(1, 5).add(new Paragraph("项目名称").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("参考范围").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("单位").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));



        table.addCell(new Cell(1, 5).add(new Paragraph("白细胞形态(BH) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("正常").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("红细胞形态(RH)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("正常 ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("白细胞计数(血WBC)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("3.50-9.50 ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("中性细胞比率(NEU%) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("40.00-75.00").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("%").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 5).add(new Paragraph("淋巴细胞比率(LYM%)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("20.00-50.00").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("%").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("单核细胞比率(MON%)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("3.00-10.00 ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("%").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("嗜碱细胞比率(BAS%) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("0.00-1.00").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("%").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("嗜酸细胞比率(EOS%)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("0.40-8.00").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("%").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("中性细胞计数(NEU#) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("1.80-6.30").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("淋巴细胞计数(LYM#) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("1.10-3.20").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("单核细胞计数(MON#) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("0.10-0.60").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        table.addCell(new Cell(1, 5).add(new Paragraph("嗜酸细胞计数(EOS#) ").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("0.02-0.52").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 5).add(new Paragraph("嗜碱细胞计数(BAS#)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("0.00-0.06").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 5).add(new Paragraph("红细胞计数（血RBC）").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("4.30-5.80").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^12/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 5).add(new Paragraph("血红蛋白(HGB)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("130-175").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("g/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));

        table.addCell(new Cell(1, 5).add(new Paragraph("血小板(PTL)").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("125.00-350.00").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 5).add(new Paragraph("10^9/L").setTextAlignment(
                TextAlignment.CENTER).setFont(font).setFontSize(12)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));


        String remark = "注意防范！";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate localDate = LocalDate.now();



        table.addCell(new Cell(1, 15).add(new Paragraph(remark).setTextAlignment(
                TextAlignment.LEFT).setFont(font).setFontSize(11)).setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE).setMinHeight(10f));
        table.addCell(new Cell(1, 15).add(new Paragraph("制表日期: " + localDate).setTextAlignment(TextAlignment.RIGHT)
                .setFont(font).setFontSize(10)).setMinHeight(10f).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(Border.NO_BORDER));
        doc.add(table);
    }

}
